function getGridPanel() {

	
	var win;
	var swin;
	var vstore = new Ext.data.JsonStore({
		autoDestroy : true,
		url : 'capitalList.action',
		storeId : 'myStore',
		// reader configs
		root : 'images',
		totalProperty : 'rowCount',
		idProperty : 'id',
		fields : ['id','CFirstType','CSecondType','CBrand','CModel','CMachineResID','CStatusUsed',
    'CStatusSell','CSignInPerson','CSignOutPerson','DSignInTime','DSignOutTime','DModifyTime',
    'CModifyPerson','IProjectID']
	});

	var grid = new Ext.grid.GridPanel({
		title : "资产信息管理",
		store : vstore,
		tbar : [{
			text : "新建",
			handler : addCapital
		}, "-", {
			text : "修改",
			handler : modifyCapital
		}, "-", {
			text : "删除",
			handler : deleteCapital
		}],
		colModel : new Ext.grid.ColumnModel({
			defaults : {
				width : 120,
				sortable : true
			},
			columns : [new Ext.grid.RowNumberer(), {
				header : '一级分类',
				width : 200,
				dataIndex : 'CFirstType'
			}, {
				header : '二级分类',
				width : 200,
				dataIndex : 'CSecondType'
			}, {
				header : '品牌',
				width : 200,
				dataIndex : 'CBrand'
			}, {
				header : '型号',
				width : 200,
				dataIndex : 'CModel'
			}, {
				header : '机器唯一码',
				width : 200,
				dataIndex : 'CMachineResID'
			}, {
				header : '使用状态',
				width : 200,
				dataIndex : 'CStatusUsed'
			}, {
				header : '销售状态',
				width : 200,
				dataIndex : 'CStatusSell'
			}, {
				header : '入库经办人',
				width : 200,
				dataIndex : 'CSignInPerson'
			}, {
				header : '出库经办人',
				width : 200,
				dataIndex : 'CSignOutPerson'
			}, {
				header : '入库时间',
				width : 200,
				dataIndex : 'DSignInTime'
			}, {
				header : '出库时间',
				width : 200,
				dataIndex : 'DSignOutTime'
			}, {
				header : '修改时间',
				width : 200,
				dataIndex : 'DModifyTime'
			}, {
				header : '修改人',
				width : 200,
				dataIndex : 'CModifyPerson'
			}, {
				header : '所属项目',
				width : 200,
				dataIndex : 'IProjectID'
			}]
		}),
		viewConfig : {
			forceFit : true
		},
		sm : new Ext.grid.RowSelectionModel({
			singleSelect : true
		}),
		width : 600,
		height : 300,
		frame : true,
		iconCls : 'icon-grid',
		bbar : new Ext.PagingToolbar({
			store : vstore, // grid and PagingToolbar using same store
			pageSize : 10
		})

	});
	vstore.load();
	
	var getRowIndex = new Ext.grid.RowSelectionModel({
	listeners:{
		rowselect:function(sm,row,rec){
			alert(row+1);
			vstore.indexOf(rec);
		}
	}
	})
	
	new Ext.Viewport({
		layout : "fit",
		items : grid
	});

	function addCapital() {
		win = new Ext.Window({
			labelAlign : 'top',
			title : '基本信息',
			modal : true,
			width : 400,
			height : 450,
			layout:'fit'
		});
		var fpanel = new Ext.form.FormPanel({
				autoHeight:true,
				autoWidth:true,
				tbar : ["->",{
			text : "读卡",
			handler : readCard
		}, "-", {
			text : "唯一码绑定",
			handler : bindUniqueCode
		}],
				items : [{
					layout : 'form',
					border : false,
					items : [{
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;机器唯一码',
						name : 'CMachineResID',
						id:'addUniqueCode'
					},{
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;一级分类',
						name : 'CFirstType'
					},{
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;二级分类',
						name : 'CSecondType'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;品牌',
						name : 'CBrand'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;类型',
						name : 'CModel'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;使用状态',
						name : 'CStatusUsed'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;销售状态',
						name : 'CStatusSell'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;入库经办人',
						name : 'CSignInPerson'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;出库经办人',
						name : 'CSignOutPerson'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;入库时间',
						name : 'DSignInTime'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;出库时间',
						name : 'DSignOutTime'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;修改人',
						name : 'CModifyPerson'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;所属项目',
						name : 'IProjectID'
					}]
			}],

			buttons : [{
				text : '保存',
				handler : insertCapital
			}, {
				text : '重置',
				handler : resetWin
			}, {
				text : '取消',
				handler : closeWin
			}]
		})
		win.add(fpanel);
		win.show();
	}

	function modifyCapital() {	
		win = new Ext.Window({
			labelAlign : 'top',
			title : '基本信息',
			modal : true,
			width : 400,
			height : 450,
			layout:'fit'
		});
		var fpanel = new Ext.form.FormPanel({
				tbar : ["->", {
			text : "唯一码绑定",
			handler : bindUniqueCodeForModify
		}],
				items : [{
					layout : 'form',
					border : false,
					items : [{
						xtype : 'hidden',
						name : 'id'
					},{
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;机器唯一码',
						name : 'CMachineResID',
						id:'modifyUniqueCode'
					},{
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;一级分类',
						name : 'CFirstType'
					},{
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;二级分类',
						name : 'CSecondType'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;品牌',
						name : 'CBrand'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;类型',
						name : 'CModel'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;使用状态',
						name : 'CStatusUsed'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;销售状态',
						name : 'CStatusSell'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;入库经办人',
						name : 'CSignInPerson'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;出库经办人',
						name : 'CSignOutPerson'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;入库时间',
						name : 'DSignInTime'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;出库时间',
						name : 'DSignOutTime'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;修改人',
						name : 'CModifyPerson'
					}, {
						xtype : 'textfield',
						width:250,
						fieldLabel : '&nbsp;&nbsp;&nbsp;&nbsp;所属项目',
						name : 'IProjectID'
					}]
			}],
			buttons : [{
				text : '保存',
				handler : saveCapital
			}, {
				text : '取消',
				handler : function() {
					win.close();
				}
			}]
		})
		var record = grid.getSelectionModel().getSelected();
		if(record==null||record==undefined){
			Ext.MessageBox.alert("提示", "请先选择一条记录！");
			return;
		}
		win.add(fpanel);
		win.show();
		win.getComponent(0).getForm().loadRecord(record);
	}

	function deleteCapital() {
		var record = grid.getSelectionModel().getSelected();
		if(record==null||record==undefined){
			Ext.MessageBox.alert("提示", "请先选择一条记录！");
			return;
		}
		var id = record.get('id');
		alert(id);
		Ext.Ajax.request({
			url : 'deleteCapital.action',
			params : {
				kid : id
			},
			callback : function() {
				Ext.Msg.alert('Success', "已经删除");
				vstore.reload();
			}
		})
	}

	function goBack() {

	}

	function saveCapital() {
		win.getComponent(0).getForm().submit({
			url : "updateCapital.action",
			success: function(form, action) {
       			Ext.Msg.alert('Success', action.result.msg);
       			win.close();
       			vstore.reload();
   			 },
    		failure: function(form, action) {
                Ext.Msg.alert('Failure', action.result.msg);
                win.close();
       			vstore.reload();
      		 }
		})
	}
	
	function insertCapital() {
		win.getComponent(0).getForm().submit({
			url : "insertCapital.action",
			success: function(form, action) {
       			Ext.Msg.alert('Success', action.result.msg);
       			win.close();
       			vstore.reload();
   			 },
    		failure: function(form, action) {
                Ext.Msg.alert('Failure', action.result.msg);
                win.close();
       			vstore.reload();
      		 }
		})
	}
	
	 function closeWin() {
					win.close();
				}
				
	 function resetWin() {
		win.getComponent(0).getForm().reset();
	}
	
	function readCard() {
					Ext.getCmp('addUniqueCode').setValue("aaa");
	}
				
	function bindUniqueCode() {
	var mstore = new Ext.data.JsonStore({
					autoDestroy: true,
				    url: 'getMachineID.action',
				    root: 'images',
				    fields : ['CMachineID','CName']

				});
				mstore.load();
	var dstore = new Ext.data.JsonStore({
					autoDestroy: true,
				    url: 'getDeviceName.action',
				    root: 'images',
				    fields : ['CMachineID','CDeviceName']

				});
	dstore.load();
	var pstore = new Ext.data.JsonStore({
					autoDestroy: true,
				    url: 'getPort.action',
				    root: 'images',
				    fields : ['CPort']

				});
	pstore.load();
	var machinecb = new Ext.form.ComboBox({
				id:'mc',
				mode : 'local',
				triggerAction : 'all',
				editable : false,
				fieldLabel : '前置机名称',
				name : 'CMachineID',
				hiddenName : 'CMachineID',
				displayField : 'CMachineID',
				valueField : 'CMachineID',
				width : 150,
				store : mstore,
				 emptyText: '请选择',
				listeners:{
					select:function(combo,record,index){
						devicecb.clearValue();
						var cMachineID = combo.value;
						devicecb.store.load({
						   url: 'getDeviceName.action',
						   params:{
						   	cMachineID:cMachineID
						   }
						});
					
					}
				}
			});
	var devicecb = new Ext.form.ComboBox({
				id:'dc',
				mode : 'local',
				triggerAction : 'all',
				editable : false,
				fieldLabel : '设备名称',
				name : 'CDeviceName',
				hiddenName : 'CDeviceName',
				displayField : 'CDeviceName',
				valueField : 'CDeviceName',
				width : 150,
				store : dstore,
		    	emptyText: '请选择',
				listeners:{
					beforequery :function(){
						if(machinecb.getStore().getCount()== 0){
							Ext.MessageBox.alert("提示", "请先选择前置机！");
						}
					},
					select:function(combo,record,index){
						portcb.clearValue();
						var cDeviceName = combo.value;
						var cMachineID = record.get('CMachineID');
						portcb.store.load({
						   url: 'getPort.action',
						   params:{
						   	cDeviceName:cDeviceName,
						   	cMachineID:cMachineID
						   }
						});
					
					}
				}
				
			});	
	var portcb = new Ext.form.ComboBox({
				id:'pc',
				mode : 'local',
				triggerAction : 'all',
				editable : false,
				fieldLabel : '监控点名称',
				name : 'CPort',
				hiddenName : 'CPort',
				displayField : 'CPort',
				valueField : 'CPort',
				width : 150,
				store : pstore,
		    	emptyText: '请选择',
				listeners:{
					beforequery :function(){
						if(devicecb.getStore().getCount()== 0){
							Ext.MessageBox.alert("提示", "请先选择设备！");
						}
					}
				}
				
			});	
	
	var ac = Ext.getCmp('addUniqueCode').getValue();
	if(ac==''){
		 Ext.Msg.alert('提示', '请先读卡获取唯一码信息！ ');
		return;
	}
	swin = new Ext.Window({
			labelAlign : 'top',
			title : '基本信息',
			modal : true,
			width : 280,
			height : 180,
			layout:'fit'
		});
		var spanel = new Ext.form.FormPanel({
				items : [{
					layout : 'form',
					border : false,
					items : [{
						xtype : 'textfield',
						fieldLabel : '机器唯一码',
						name : 'CMachineResID',
						id:'uniqueCode'
					},machinecb,devicecb,portcb]
			}],

			buttons : [{
				text : '绑定',
				handler : bindUniCode
			},  {
				text : '关闭',
				handler : closeSWin
			}]
		})
		swin.add(spanel);
		swin.show();
		Ext.getCmp('uniqueCode').setValue(Ext.getCmp('addUniqueCode').getValue());
		
	}
	
	function bindUniCode() {
		var uni=Ext.getCmp('uniqueCode').getValue();
		var mc=Ext.getCmp('mc').getValue();
		var dc=Ext.getCmp('dc').getValue();
		var pc=Ext.getCmp('pc').getValue();
		if(mc==''&&dc==''&&pc==''){
			Ext.MessageBox.alert("提示", "请至少选择一个设备进行绑定！");
			return;
		}
		Ext.Ajax.request({
			url : 'bindUniCode.action',
			params : {
				CMachineResID : uni,
				cMachineID : mc,
				cDeviceName : dc,
				cPort : pc
			},
			success : function(response,opts) {
				Ext.MessageBox.alert("提示", "绑定成功！");
			}
		})
	}
				
				function closeSWin() {
					swin.close();
					}				
				
			function bindUniqueCodeForModify() {var mstore = new Ext.data.JsonStore({
					autoDestroy: true,
				    url: 'getMachineID.action',
				    root: 'images',
				    fields : ['CMachineID','CName']

				});
				mstore.load();
	var dstore = new Ext.data.JsonStore({
					autoDestroy: true,
				    url: 'getDeviceName.action',
				    root: 'images',
				    fields : ['CMachineID','CDeviceName']

				});
	dstore.load();
	var pstore = new Ext.data.JsonStore({
					autoDestroy: true,
				    url: 'getPort.action',
				    root: 'images',
				    fields : ['CPort']

				});
	pstore.load();
	var machinecb = new Ext.form.ComboBox({
				id:'mc',
				mode : 'remote',
				triggerAction : 'all',
				editable : false,
				fieldLabel : '前置机名称',
				name : 'CMachineID',
				hiddenName : 'CMachineID',
				displayField : 'CMachineID',
				valueField : 'CMachineID',
				width : 150,
				store : mstore,
				 emptyText: '请选择',
				listeners:{
					select:function(combo,record,index){
						devicecb.clearValue();
						var cMachineID = combo.value;
						devicecb.store.load({
						   url: 'getDeviceName.action',
						   params:{
						   	cMachineID:cMachineID
						   }
						});
					
					}
				}
			});
	var devicecb = new Ext.form.ComboBox({
				id:'dc',
				mode : 'remote',
				triggerAction : 'all',
				editable : false,
				fieldLabel : '设备名称',
				name : 'CDeviceName',
				hiddenName : 'CDeviceName',
				displayField : 'CDeviceName',
				valueField : 'CDeviceName',
				width : 150,
				store : dstore,
		    	emptyText: '请选择',
				listeners:{
					beforequery :function(qe){
						alert();
					},
					select:function(combo,record,index){
						portcb.clearValue();
						var cDeviceName = combo.value;
						var cMachineID = record.get('CMachineID');
						portcb.store.load({
						   url: 'getPort.action',
						   params:{
						   	cDeviceName:cDeviceName,
						   	cMachineID:cMachineID
						   }
						});
					
					}
				}
				
			});	
	var portcb = new Ext.form.ComboBox({
				id:'pc',
				mode : 'remote',
				triggerAction : 'all',
				editable : false,
				fieldLabel : '监控点名称',
				name : 'CPort',
				hiddenName : 'CPort',
				displayField : 'CPort',
				valueField : 'CPort',
				width : 150,
				store : pstore,
		    	emptyText: '请选择',
				listeners:{
					beforequery :function(qe){
						if(devicecb.getStore().getCount()== 0){
							Ext.MessageBox.alert("提示", "请先选择设备！");
						}
					}
				}
				
			});	
	
	var ac = Ext.getCmp('modifyUniqueCode').getValue();
	if(ac==''){
		 Ext.Msg.alert('提示', '请先读卡获取唯一码信息！ ');
		return;
	}
	swin = new Ext.Window({
			labelAlign : 'top',
			title : '基本信息',
			modal : true,
			width : 280,
			height : 180,
			layout:'fit'
		});
		var spanel = new Ext.form.FormPanel({
				items : [{
					layout : 'form',
					border : false,
					items : [{
						xtype : 'textfield',
						fieldLabel : '机器唯一码',
						name : 'CMachineResID',
						id:'uniqueCode'
					},machinecb,devicecb,portcb]
			}],

			buttons : [{
				text : '绑定',
				handler : bindUniCode
			},  {
				text : '关闭',
				handler : closeSWin
			}]
		})
		swin.add(spanel);
		swin.show();
		Ext.getCmp('uniqueCode').setValue(Ext.getCmp('modifyUniqueCode').getValue());
		
	}		
}
